from node import Node

class DynamicQueue:
    def __init__(self):
        """
        Initializes a new instance of the DynamicQueue class that is empty.
        """
        self.__head  = None
        self.__tail  = None
        self.__count = 0
    
    @property
    def count(self):
        """
        Gets the number of elements contained in the DynamicQueue.
        """
        return self.__count    
    
    def enqueue(self, item):
        """
        Adds and elment to the end of the DynamicQueue.
        """
        node             = Node()
        node.information = item
        node.next        = None
        
        if (self.__head == None):
            self.__head = self.__tail = node
        else:
            self.__tail.next = node
            self.__tail      = node
        
        self.__count += 1
        
    def dequeue(self):
        """
        Removes and returns the object at the beginning of the DynamicQueue.
        """
        if (self.__head == None):
            print "The queue is empty."
            return None
        
        information = self.__head.information
        self.__head = self.__head.next
        self.__count -= 1
        
        return information
    
    def peek(self):
        """
        Returns the object at the beginning of the DynamicQueue without removing it.
        """
        if (self.__head == None):
            print "The queue is empty."
            return None
        
        return self.__head.information       
        